package pr.iceworld.fernando.commonbase.model;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public enum Gender implements BaseValue, ModelBase {
    /**
     * 女
     */
    F(0),
    /**
     * 男
     */
    M(1),
    /**
     * 未选择
     */
    NA(5);


    private static Map<Integer, Gender> valueMap = new HashMap<>();

    static {
        for(Gender gender : Gender.values()) {
            valueMap.put(gender.value, gender);
        }
    }

    private int value;
    Gender(int value) { this.value = value; }

    @Override
    public int getValue() { return this.value; }

    public static Gender getByValue(int value) {
        Gender result = valueMap.get(value);
        if(Objects.isNull(result)) {
            throw new IllegalArgumentException("No element matches " + value);
        }
        return result;
    }
}
